package cc.tuhaolicai.mt.user.mobile.controller.root;

import cc.tuhaolicai.mt.user.mobile.annotation.Mapping;
import cc.tuhaolicai.mt.user.mobile.business.handler.BusinessHandler;
import cc.tuhaolicai.mt.user.mobile.business.model.Workflow;
import cc.tuhaolicai.mt.user.mobile.business.util.WorkflowUtil;
import cc.tuhaolicai.mt.user.mobile.controller.BaseController;
import cc.tuhaolicai.mt.user.mobile.service.ChainHandler1;
import cc.tuhaolicai.mt.user.mobile.service.ChainHandler2;
import cc.tuhaolicai.mt.user.mobile.service.ChainHandler3;
import cc.tuhaolicai.mt.user.mobile.tool.ToolDate;
import com.google.common.collect.Maps;

import java.util.HashMap;

/**
 * @author chenli
 * @create 2017-10-12
 */
@Mapping(value = "/test", viewPath = "/admin/chain")
public class TestController extends BaseController {

    public void index(){
        Integer startNum = getParaToInt(0);
        Workflow workflow = WorkflowUtil.buildWorkflow("测试业务链", String.valueOf(ToolDate.getDate().getTime()));
        BusinessHandler start = new ChainHandler1();
        start.setName("业务1");
        BusinessHandler businessHandler2 = new ChainHandler2();
        businessHandler2.setName("业务2");
        BusinessHandler businessHandler3 = new ChainHandler3();
        businessHandler3.setName("业务3");
        start.setNextHandler(businessHandler2);
        businessHandler2.setNextHandler(businessHandler3);
        HashMap<String, Object> params = Maps.newHashMap();
        params.put("start",startNum);
        start.start(params,workflow);
        renderJson("成功");
    }
}